package controller_test

import (
	"context"
	"testing"

	"gitlab.com/go-course-project/go17/book/controller"
	"gitlab.com/go-course-project/go17/book/exception"
	"gitlab.com/go-course-project/go17/book/model"
)

func TestGetBook(t *testing.T) {
	book := controller.NewBookController()
	ins, err := book.GetBook(context.Background(), &controller.GetBookRequest{
		Isbn: 100,
	})

	if err != nil && exception.IsNotFound(err) {
		t.Log("is not found error")
	}
	// if errors.Is(err, gorm.ErrRecordNotFound) {
	// 	t.Log("is not found error")
	// }
	// if err.Error() == "record not found" {
	// 	t.Log(" string equal is not found error")
	// }
	if err != nil {
		t.Fatal(err)
	}
	t.Log(ins)
}

// INSERT INTO `books` (`title`,`author`,`price`,`is_sale`) VALUES ('Go语言','will',10,NULL)
//
//	{
//		"isbn": 5,
//		"title": "Go语言",
//		"author": "will",
//		"price": 10,
//		"is_sale": null
//	  }
func TestCreateBook(t *testing.T) {
	book := controller.NewBookController()
	ins, err := book.CreateBook(context.Background(), &model.BookSpec{
		Author: "will",
		Price:  10,
		Title:  "Go语言",
	})
	if err != nil {
		t.Fatal(err)
	}
	t.Log(ins)
}
